<script setup>
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Delete,
  Edit
} from '@element-plus/icons-vue'
// ------------------------------用户角色搜索
const formInline = reactive({
    tagId: '',
    tagName: '',
    tagLabel: '',
})

const onSubmit = () => {
    console.log('submit!')
}
// ------------------------------用户角色数据
let user_tag = reactive([
    {
        id: 10001, 
        name: "common",
        label: "普通",
        addTime: "2024-08-10 11:00:11",
        status: 0,
    },
    {
        id: 10002, 
        name: "vedio",
        label: "视频",
        addTime: "2024-08-10 11:00:11",
        status: 0,
    },
    {
        id: 10003, 
        name: "audio",
        label: "音频",
        addTime: "2024-08-10 11:00:11",
        status: 0,
    },
    {
        id: 10004, 
        name: "zhibo",
        label: "直播",
        addTime: "2024-08-10 11:00:11",
        status: 0,
    },
    {
        id: 10005, 
        name: "xiaofei_2",
        label: "消费2级",
        addTime: "2024-08-10 11:00:11",
        status: 0,
    },

])

// ------------------------ 分页

const currentPage = ref(1)
const pageSize = ref(100)
const size = ref('default')
const background = ref(false)
const disabled = ref(false)

const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}

// ---------------------- 删除用户管理组操作
function showConfirm(group) {
    ElMessageBox.confirm(
    '确定要删除 ' + group.label +' 用户标签吗?',
    '警告信息',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
    //   deleteUser(user)
        ElMessage({
            type: 'info',
            message: '管理员执行了删除操作',
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '管理员取消了删除操作',
      })
    })
    
}

// 删除用户的函数：参数user就是要删除的用户
// function deleteUser(user) {
//     // 查询用户在数组中的索引
//     let index = users.findIndex(item => item.id === user.id)
//     // 删除用户数据
//     users.splice(index, 1)
//     // 提示删除成功
//     ElMessage({
//         type: 'success',
//         message: '管理员成功删除了用户 ' + user.username,
//       })
// }

// // ------------------ 新增用户操作 
// import DialogUserCreate from '../../components/DialogUserCreate.vue'
// // 声明变量控制弹窗显示/隐藏
// let userDialogCreate = ref(false)
// // 准备函数：显示对话框
// function showCreateDialog() {
//     userDialogCreate.value = true
// }
// // 准备函数：隐藏对话框
// function hideCreateDialog() {
//     userDialogCreate.value = false
// }
// // 新增用户数据：参数user就是子组件告诉父组件要新增的用户
// function createUser(user) {
//     // 计算新用户的id
//     let id = users[0].id + 1
//     // 复制一份用户数据
//     let newUser = {...user}
//     // 给新数据添加id属性
//     newUser.id = id
//     // 新增用户
//     users.unshift(newUser)
// }


</script>
<template>
    <div class="p-header">
        <h2>标签数据管理</h2>
        <el-button type="primary" @click="showCreateDialog">新增标签</el-button>
    </div>
    <!-- 新增管理组弹窗 -->
    <!-- <DialogUserCreate :dialogFormVisible="userDialogCreate"
        @createUserEvent="createUser"
        @closeCreateEvent="hideCreateDialog"></DialogUserCreate> -->

    <el-divider>标签信息搜索</el-divider>
    <el-card>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="ID：">
                <el-input v-model="formInline.tagId" placeholder="请输入角色ID" clearable />
            </el-form-item>
            <el-form-item label="名称：">
                <el-input v-model="formInline.tagName" placeholder="请输入标签name" clearable />
            </el-form-item>
            <el-form-item label="描述：">
                <el-input v-model="formInline.tagLabel" placeholder="请输入标签label" clearable />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
            </el-form-item>
        </el-form>
    </el-card>
    <el-divider>标签信息展示</el-divider>
    <el-table :data="user_tag" style="width: 100%">
        <el-table-column label="ID" prop="id" width="80"/>
        <el-table-column label="名称" prop="name"/>
        <el-table-column label="描述" prop="label">
            <template #default="{ row }">
                <el-tag type="success">{{ row.label }}</el-tag>
            </template>
        </el-table-column>
        <el-table-column label="状态" prop="status">
            <template #default="{ row }">
                <el-tag type="primary" v-if="row.status==0">正常</el-tag>
                <el-tag type="danger" v-else-if="row.status==1">锁定</el-tag>
            </template>
        </el-table-column>
        <!-- {
        id: 40006, username: 'wx_17765007861', nickname: 'Eluck', avator: '', phone: '',
        balance: 50, cumCon: 0, ticket: 0.00, cumTicket: 0,
        invitation: '2CE0F8', regDevice: 'android',
        regTime: '2024-08-26 10:08:02',
        lastLogin: '2024-08-26 12:30:12',
        lastIp: '223.104.205.215',
        status: 0
    } -->
        <el-table-column align="right" fixed="right" width="220">
            <template #default="scope">
                <el-button type="primary" :icon="Edit" circle />
                <el-button type="danger" :icon="Delete" circle @click="showConfirm(scope.row)"/>
            </template>
        </el-table-column>
    </el-table>

    <el-pagination
      background
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[100, 200, 300, 400]"
      :size="size"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="1000"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
</template>
<style scoped>
.demo-form-inline .el-input {
    --el-input-width: 220px;
}

.demo-form-inline .el-select {
    --el-select-width: 100px;
    font-size: 14px;
}

.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}

.el-pagination{
    margin-top:20px;
}

.p-header{
    display:flex;
    justify-content: space-between;
}
</style>